//
// Created by yyl on 2018/6/6.
//

#ifndef MYMUSIC_YFFMPEG_H
#define MYMUSIC_YFFMPEG_H

#include "CallJava.h"
#include "YAudio.h"
#include "YVideo.h"

extern "C" {
#include <libavformat/avformat.h>
#include <libavutil/time.h>
};


class YFFmpeg {
public:
    CallJava *callJava = NULL;
    const char *url = NULL;
    pthread_t decodeThread;
    AVFormatContext *mAvFormatContext = NULL;
    YVideo *video=NULL;
    YAudio *audio = NULL;
    PlayStatus *playStatus = NULL;
    pthread_mutex_t init_mutex;
    pthread_mutex_t seek_lock;
    int64_t duration = 0;
    bool isExit = false;
    bool supportMediacodec = false;

    const AVBitStreamFilter *bsFilter = NULL;
public:
    YFFmpeg(CallJava *callJava1, const char *url, PlayStatus *playStatus);

    ~YFFmpeg();

    void parpared();

    void start();

    void decodeFFmpegThread();

    int changePlayState(bool isPlay);

    void release();

    void seek(int64_t secods);


    int64_t getDuration();
    double getCurrentTime();
    void setVolume(int percent);

    void setMute(int mute);

    void setPitch(double pitch);

    void setSpeed(double speed);
    void supportMediaCodecHardware();
    int getSampleRate();
    void startRecord(bool isRecord);

    int getCodecContext( AVCodecParameters *avCodecParameters,AVCodecContext **avCodecContext);
private:
    void exitError();
};


#endif //MYMUSIC_YFFMPEG_H
